package Modelo;
import Conexion.Conexion;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SIS_PERFILES_ROLES{
	private double ID_PERFILES;
	private double ID_ROLES;
        private Conexion con = null;
        
	public SIS_PERFILES_ROLES(){}

	public SIS_PERFILES_ROLES(double ID_PERFILES,double ID_ROLES){
		this.ID_PERFILES =ID_PERFILES;
		this.ID_ROLES =ID_ROLES;
	}

	public boolean Insertar(){
		try{
			String consulta = "insert into BROKER.SIS_PERFILES_ROLES(ID_PERFILES,ID_ROLES) VALUES ("+ID_PERFILES+","+ID_ROLES+")";
			con.EjecutarSentencia(consulta);
			return true;
		}
		catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
        
        public boolean Desabilitar(double id_rol, double id_perfil)
        {
            try{
                String consulta = "delete from BROKER.SIS_PERFILES_ROLES where ID_ROLES = "+id_rol+" and ID_PERFILES = "+id_perfil;
                con.EjecutarSentencia(consulta);
                return true;
            }
            catch(Exception e){
                e.printStackTrace();
                return false;
            }
	}
        
        public boolean Abilitar(double id_rol, double id_proceso) throws SQLException
        {
            String consulta = "insert into BROKER.SIS_PERFILES_ROLES(ID_ROLES,ID_PERFILES) VALUES ("+id_rol+","+id_proceso+")";
            con.EjecutarSentencia(consulta);
            return true;
	}

	public SIS_PERFILES_ROLES BuscarXid(double idrol, double idperfil){
		try{String consulta = "select * from BROKER.SIS_PERFILES_ROLES where ID_PERFILES = "+idperfil+" and ID_ROLES = "+idrol;
			ResultSet rs = con.EjecutarConsulta(consulta);
			return Cargar(rs).get(0);}
		catch(Exception e){
			e.printStackTrace();}
			return null;
	}

	public List<SIS_PERFILES_ROLES> Todos(){
		try{String consulta = "select * from BROKER.SIS_PERFILES_ROLES";
			ResultSet rs = con.EjecutarConsulta(consulta);
			return Cargar(rs);}
		catch(Exception e){
			e.printStackTrace();}
			return null;
	}

        public List<SIS_PERFILES_ROLES> TodosLosActivos(double perfil){
		try{String consulta = "select * from BROKER.SIS_PERFILES_ROLES where ID_PERFILES = "+perfil;
			ResultSet rs = con.EjecutarConsulta(consulta);
			return Cargar(rs);}
		catch(Exception e){
			e.printStackTrace();}
			return null;
	}     //
        public List<SIS_PERFILES_ROLES> buscarTodosLosActivos(double perfil, String descripcion){
		try{String consulta = "select pr.ID_PERFILES, pr.ID_ROLES from BROKER.SIS_PERFILES_ROLES pr ,BROKER.SIS_ROLES r where pr.ID_ROLES=r.ID  and pr.ID_PERFILES = "
                        +perfil+ " AND (UPPER (r.DESCRIPCION) like  UPPER('%"+descripcion+"%'))";
			ResultSet rs = con.EjecutarConsulta(consulta);
			return Cargar(rs);}
		catch(Exception e){
			e.printStackTrace();}
			return null;
	} 
        
	public List<SIS_PERFILES_ROLES> Cargar(ResultSet rs){
		try{
			List<SIS_PERFILES_ROLES> lista = new ArrayList<SIS_PERFILES_ROLES>();
			while(rs.next()){
				SIS_PERFILES_ROLES objeto = new SIS_PERFILES_ROLES();

				objeto.setID_PERFILES(rs.getDouble("ID_PERFILES"));
				objeto.setID_ROLES(rs.getDouble("ID_ROLES"));
                                objeto.setCon(con);
				lista.add(objeto);
			}
			return lista;
		}
		catch(SQLException ex){
			ex.printStackTrace();
		return null;}
	}

	public double getID_PERFILES(){
		return ID_PERFILES;
	}
	public void setID_PERFILES(double ID_PERFILES){
		this.ID_PERFILES=ID_PERFILES;
	}

	public double getID_ROLES(){
		return ID_ROLES;
	}
	public void setID_ROLES(double ID_ROLES){
		this.ID_ROLES=ID_ROLES;
	}

    public Conexion getCon() {
        return con;
    }

    public void setCon(Conexion con) {
        this.con = con;
    }
        
        
}
